package user

import (
	"gin-project-01/gin-step02/gin07-controller/controllers"
	"github.com/gin-gonic/gin"
	"math/rand"
	"net/http"
)

// UserController
// @Description: 定义一个controller结构体，继承 BaseController，再在路由中注册
type UserController struct {
	controllers.BaseController //继承 controllers.BaseController
}

func (u UserController) Index(c *gin.Context) {
	c.String(http.StatusOK, "%s", "用户首页")
}

func (u UserController) Detail(c *gin.Context) {
	c.String(http.StatusOK, "%s", "用户详情")
}

func (u UserController) Delete(c *gin.Context) {
	c.String(http.StatusOK, "%s", "删除用户")
}

func (u UserController) Add(c *gin.Context) {
	num := rand.Intn(10) + 1
	if num > 5 {
		u.Success(c) //调用父类的Success方法
	} else {
		u.Error(c) //调用父类的Error方法
	}
}
